import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/component/component.dart';
import 'package:leader_help/utils/util.dart';

Future showDropDownList({
  required List<String> list,
  required Function(int)? onTap,
  int selectedIndex = -1,
  double left = 0,
  double top = 0,
  double right = 0,
  double height = 200,
  bool needBarrierColor = false,
}) async {
  await Get.dialog(
    Padding(
      padding: EdgeInsets.fromLTRB(left, top, right, 0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        children: [
          Container(
            // margin: EdgeInsets.fromLTRB(left, top, right, 0),
            width: Get.width,
            height: height,
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.vertical(bottom: Radius.circular(4.r)),
            ),
            child: ListView.separated(
              itemCount: list.length,
              separatorBuilder: (context, index) {
                return Container(
                  margin: EdgeInsets.symmetric(horizontal: 10.r),
                  height: 0.5,
                  color: ColorsUtil.separator,
                );
              },
              itemBuilder: (context, index) {
                var _item = list[index];
                return ListTile(
                  onTap: () {
                    if (onTap != null) {
                      onTap(index);
                    }
                    Get.back();
                  },
                  title: Text(
                    _item,
                    style: pfMediumStyle(
                        color: selectedIndex == index
                            ? ColorsUtil.red
                            : ColorsUtil.title,
                        fontSize: 13.sp),
                  ),
                  trailing: selectedIndex == index
                      ? Icon(
                          Icons.check,
                          size: 25.r,
                        )
                      : null,
                  selectedColor: ColorsUtil.red,
                  selected: selectedIndex == index,
                );
              },
            ),
          ),
          // Row(
          //   children: [
          //     Expanded(
          //       child: InkWell(
          //           child: Container(
          //         alignment: Alignment.center,
          //         color: const Color(0xffF5A79F),
          //         height: buttonHeight,
          //         child: Text(
          //           '取消',
          //           style: TextStyle(color: Colors.white, fontSize: 14.sp),
          //         ),
          //       )),
          //     ),
          //     Expanded(
          //       child: InkWell(
          //           child: Container(
          //         alignment: Alignment.center,
          //         color: ColorsUtil.red,
          //         height: buttonHeight,
          //         child: Text(
          //           '确定',
          //           style: TextStyle(color: Colors.white, fontSize: 14.sp),
          //         ),
          //       )),
          //     ),
          //   ],
          // )
        ],
      ),
    ),
    // useSafeArea: false,
    barrierDismissible: true,
    barrierColor: needBarrierColor ? null : Colors.white.withAlpha(0),
  );
}
